<?php
/* 
-----------------------------------------------------------------
Copyright (c) 2010 25Solutions   All Rights Reserved.

This software is the confidential and proprietary information
of 25Solutions ("Confidential Information").
You shall not disclose such Confidential Information and shall
use it only in accordance with the terms of the license
agreement you entered into with 25Solutions
-----------------------------------------------------------------
 */

include(dirname(__FILE__).'/../../bootstrap/Doctrine.php');

$t = new lime_test(11);
//1
$t->comment('->findOneByName()');
$template = Doctrine_Core::getTable('Template')->findOneByName('Subscription');
$t->is($template->getName(), 'Subscription', '->findOneByName() return the template with given name ');
//2
$t->comment('->getLinkNames()');
$t->is($template->getLinkNames(), array('arcadja'), '->getLinkNames() returns links placeholder in the template');
//3
$t->comment('LinkTable->findLinkByNameAndTemplate()');
//$link = Doctrine_Core::getTable('Link')->findLinkByNameAndTemplate('arcadja', $template);
$link = Doctrine::getTable('Link')->findOneByNameAndTemplate_id('arcadja', $template->getTemplateId());
$t->is($link->getName(), 'arcadja', 'LinkTable->findLinkByNameAndTemplate() loads Link object related to the template');
//4
$t->comment('->getLinks()');
$links = $template->getLinks();
$t->ok(sizeof($links->toArray())>0, 'getLinks() return the Template link(s)');
//5
$t->comment('->getLink()');
$link = $template->getLink('arcadja');
$t->is($link->getName(), 'arcadja', '->getLink() return the link with the given name');
//6
$t->comment('->getOldLinkNames()');
$linkNames = $template->getOldLinkNames();
$expected = array ('arcadja');
$t->is($linkNames, $expected, '->getOldLinkNames() return the old link names');
//7
$t->comment('->getLinkNames()');
$template->setBodyHtml('{@ciccio}, {@pasticcio}');
$linkNames = $template->getLinkNames();
$expected = array ('ciccio', 'pasticcio');
$t->is($linkNames, $expected, '->getLinkNames() return the new link names');
//8
$t->comment('->refreshTemplate()');
$template->refreshTemplate();
$link = $template->getLink('arcadja');
$t->is($link->getName(), 'arcadja', '->refreshLinks() return arcadja ');
//9
$links = $template->getLinks();
$t->is(sizeof($links->toArray()),3, 'getLinks() now return 3 links');
//10
$template = Doctrine_Core::getTable('Template')->findOneByName('springpromotion');
$template->refreshTemplate();
$links = $template->getLinks();
$t->is(sizeof($links->toArray()),1, 'getLinks() return 1 links');
//11
$template = Doctrine_Core::getTable('Template')->findOneByName('Iscrizione');
$links = $template->getNormalLinks();
$t->ok(sizeof($links)>0, 'getNormalLinks() return the Template standard link(s)');